<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <h1>这个html会在3000端口下运行</h1>
  <button>发送ajax请求4000端口的路由</button>
  <script>
    // 发送ajax到4000端口服务器的数据
    /*
      ajax发送的地址：http://localhost:3000
      ajax请求的地址：http://localhost:4000/getdata
    */
    let btn = document.querySelector("button");
    btn.onclick = function () {
      let xhr = new XMLHttpRequest();
      xhr.open("get", "http://localhost:4000/getdata");
      xhr.send();
      xhr.onload = function () {
        console.log(xhr.responseText);
      }
    }
  </script>
</body>

</html>